from django.db import models
from author.models import Author
from publisher.models import Publisher

# Create book models here.


class Book(models.Model):
    """ 书籍类 """

    title = models.CharField(max_length=32, verbose_name='书名')
    publish_date = models.DateField(verbose_name='出版时间')
    # 一对多外键   author : book= 1 : n
    author = models.ForeignKey(Author, on_delete=models.PROTECT)
    # 多对多外键   book : publisher = N : M
    publishers = models.ManyToManyField(Publisher)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '书籍'  # 在Django自带的admin后台中显示的名字
        verbose_name_plural = '书籍'
